package com.atguigu.srb.core.controller.admin;

import com.atguigu.srb.common.utils.PageUtils;
import com.atguigu.srb.common.utils.R;
import com.atguigu.srb.core.service.BorrowerService;
import com.atguigu.srb.core.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.vo.BorrowerDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(tags = "借款人管理")
@RestController
@RequestMapping("/admin/core/borrower")
@Slf4j
public class AdminBorrowerController {

    @Resource
    private BorrowerService borrowerService;

    @ApiOperation("获取借款人分页列表")
    @GetMapping("/list")
    public R listPage(@RequestParam Map<String, Object> params) {
        PageUtils page = borrowerService.queryPage(params);
        return R.ok().put("page", page);
    }


    @ApiOperation("获取借款人信息")
    @GetMapping("/show/{id}")
    public R showDetial(@ApiParam(value = "借款人id", required = true) @PathVariable("id") Long id) {
        BorrowerDetailVO borrowerDetailVO= borrowerService.getBorrowerDetailVOById(id);
        return R.ok().put("borrowerDetailVO", borrowerDetailVO);
    }

    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO) {
        borrowerService.approval(borrowerApprovalVO);
        return R.ok("审核通过");
    }


}
